﻿
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using API.EntityModels;


namespace API.Helpers
{
    public static class ConnectionHelper
    {
        private static readonly ThreadLocal<POSEntities> _threadLocal = new ThreadLocal<POSEntities>(() => null);

        public static POSEntities GetSharedEntityConnectionForRead()
        {
            if (_threadLocal.Value == null || _threadLocal.Value.Disposed)
                _threadLocal.Value = new POSEntities();
            return _threadLocal.Value;
        }

        public static POSEntities GetEntityConnection()
        {
            return new POSEntities();
        }

        public static SqlConnection GetSqlConnection()
        {
            return new SqlConnection(ConfigurationManager.ConnectionStrings["POSEntities"].ConnectionString);

        }
    }
}
